package com.qdxwx.data.service.bank;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.data.mapper.bank.BankCardMapper;
import com.qdxwx.models.bank.BankCard;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Service
public class BankCardServiceImpl  implements BankCardService {

    @Autowired
    private BankCardMapper bankCardMapper;

    @Override
    public long insert(BankCard bankCard) {
        bankCard.setCreateTime(LocalDateTime.now());
        return bankCardMapper.insertBankCard(bankCard);
    }

    @Override
    public List<BankCard> getList(BankCard bankCard, PageRequest page) {
        return bankCardMapper.selectList(bankCard, page);
    }

    @Override
    public int count(BankCard bankCard) {
        return bankCardMapper.selectCount(bankCard);
    }

    @Override
    public BankCard getByInfoId(long infoId, String type) {
        BankCard bankCard = new BankCard();
        bankCard.setInfoId(infoId);
        bankCard.setType(type);
        List<BankCard> list = getList(bankCard, null);
        return list.size() > 0 ? list.get(0) : null;
    }

    @Override
    public BankCard get(long id) {
        if(id < 1) return null;
        return bankCardMapper.selectById(id);
    }
}
